package com.example.springdata.multithread;

import cn.hutool.core.thread.ThreadUtil;
import com.mysql.cj.util.TimeUtil;

import java.util.concurrent.TimeUnit;

public class Hero {
    private String name;
    private float hp;
    private int damage;
    public boolean isDead(){
        return this.hp>0?false:true;
    }

    public Hero() {
    }

    public Hero(String name) {
        this.name = name;
    }

    public Hero(String name, float hp, int damage) {
        this.name = name;
        this.hp = hp;
        this.damage = damage;
    }

    public void attachHero(Hero h){
        ThreadUtil.sleep(10, TimeUnit.SECONDS);
        h.setHp(h.getHp()-this.getDamage());
        System.out.println(this.getName()+"正在攻击"+h.getName()+","+h.getName()+"的血变成了"+h.getHp());
        if(h.isDead()){
            System.out.println(h.getName()+" is dead!");
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public float getHp() {
        return hp;
    }

    public void setHp(float hp) {
        this.hp = hp;
    }

    public int getDamage() {
        return damage;
    }

    public void setDamage(int damage) {
        this.damage = damage;
    }
}
